<?php
namespace LPCISII\PHP2012Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;

use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @ORM\Entity
  * @ORM\Table(name="utilisateurs")
  */
class Utilisateur implements UserInterface {
	
	/**
	  * @ORM\Id
	  * @ORM\Column(type="integer")
	  * @ORM\GeneratedValue(strategy="AUTO")
	  * @ORM\ManyToMany(targetEntity="Commandes")
	  */
    protected $idU;
	
	/**
	  * @ORM\Column(type="string")
	  */
    protected $login;

	/**
	  * @ORM\Column(type="string")
	  */
	protected $mdp;
	
	/**
	  * @ORM\Column(type="string")
	  */
	protected $nom;
	
	/**
	  * @ORM\Column(type="string")
	  */
	protected $prenom;
	
	/**
	  * @ORM\Column(type="string")
	  */
	protected $rue;
	
	/**
	  * @ORM\Column(type="string")
	  */
	protected $ville;
	
	/**
	  * @ORM\Column(type="integer")
	  */
	protected $type;
    
	   /**
	     * @var ArrayCollection Commandes $commandes
	     * Owning Side
	     *
	     * @ORM\ManyToMany(targetEntity="Commandes", inversedBy="idCo", cascade={"persist", "merge"})
	     * @ORM\JoinTable(name="historique",
	     *   joinColumns={@ORM\JoinColumn(name="idUtilisateur", referencedColumnName="idU")},
	     *   inverseJoinColumns={@ORM\JoinColumn(name="idCommande", referencedColumnName="idCo")}
	     * )
	     */
	protected $commandes;
        /**
         * @var string $salt
         *
         * @ORM\Column(name="salt", type="string", length=255)
         */
        protected $salt;
		
	/**
	  * @ORM\Column(type="string")
	  */
	protected $email;		

	public function getIdU() {
		return $this->idU;
	}
	
	public function setIdU($idU) {
		$this->idU = $idU;
	}

	public function getLogin() {
        return $this->login;
    }

    public function setLogin($login) {
        $this->login = $login;
    }

    public function getMdp() {
        return $this->mdp;
    }

    public function setMdp($mdp) {
        $this->mdp = $mdp;
    }
	
	public function getNom() {
        return $this->nom;
    }

    public function setNom($nom) {
        $this->nom = $nom;
    }
	
	public function getPrenom() {
        return $this->prenom;
    }

    public function setPrenom($prenom) {
        $this->prenom = $prenom;
    }
	
	public function getRue() {
        return $this->rue;
    }

    public function setRue($rue) {
        $this->rue = $rue;
    }
	
	public function getVille() {
        return $this->ville;
    }

    public function setVille($ville) {
        $this->ville = $ville;
    }
	
	public function getType() {
        return $this->type;
    }

    public function setType($type) {
        $this->type = $type;
    }

    public function __construct()
    {
        $this->commandes = new \Doctrine\Common\Collections\ArrayCollection();
        $this->isActive = true;
        $this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
    }
    
    /**
     * Add commandes
     *
     * @param LPCISII\PHP2012Bundle\Entity\Commandes $commandes
     */
    public function addCommandes(\LPCISII\PHP2012Bundle\Entity\Commandes $commandes)
    {
        $this->commandes[] = $commandes;
    }

    /**
     * Get commandes
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getCommandes()
    {
        return $this->commandes;

    }

    public function equals(UserInterface $user) {
        return $user->getUsername() === $this->login;
    }

    public function eraseCredentials() {
        
    }

    public function getPassword() {
        return $this->mdp;
    }

    public function getRoles() {
        return array('ROLE_USER');
    }

    public function getSalt() {
         return $this->salt;
    }

    public function getUsername() {
        $this->login;
    }

    /**
     * Set salt
     *
     * @param string $salt
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;
    }
	
	public function getEmail() {
		return $this->email;
	}
	
	public function setEmail($email) {
		$this->email = $email;
	}

}